//
//  HCFindHeaderView.m
//  HappyChildren
//
//  Created by WillyZhao on 2016/12/29.
//  Copyright © 2016年 WillyZhao. All rights reserved.
//

#import "HCFindHeaderView.h"
#import "HCFindNaviView.h"


@interface HCFindHeaderView () <HCFindHeaderButtonClickedDelegate,NaviViewDelegate>
{
    HCFindNaviView *naviView;
}

@end

@implementation HCFindHeaderView

-(instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self loadSubCustomView:frame];
    }
    return self;
}

-(void)loadSubCustomView:(CGRect)frame {
    self.backgroundColor = YBKRGBCOLOR(241, 241, 241, 1);
    
    CGFloat h = YBKAdaptiveH(90);
    frame = CGRectMake(frame.origin.x, frame.origin.y, frame.size.width, frame.size.height - h);
    
    //积分商城
    HCFindHeaderButton *scoreStore = [[HCFindHeaderButton alloc] initWithFrame:CGRectMake(3, 0, (frame.size.width - 6 - YBKAdaptiveW(5))/2.0, (frame.size.height - YBKAdaptiveH(5))/2.0) andStyle:HCFindHeaderButtonScoreStore];
    scoreStore.backgroundColor = [UIColor whiteColor];
    scoreStore.delegate = self;
    scoreStore.tag = 1;
    [self addSubview:scoreStore];
    
    //门店热榜
    HCFindHeaderButton *hotStore = [[HCFindHeaderButton alloc] initWithFrame:CGRectMake(scoreStore.frame.size.width+scoreStore.frame.origin.x+YBKAdaptiveW(5), 0, scoreStore.frame.size.width, scoreStore.frame.size.height) andStyle:HCFindHeaderButtonHotStore];
    hotStore.tag = 2;
    hotStore.delegate = self;
    hotStore.backgroundColor = [UIColor whiteColor];
    [self addSubview:hotStore];
    
    //店家推荐
    HCFindHeaderButton *storeRecom = [[HCFindHeaderButton alloc] initWithFrame:CGRectMake(3, scoreStore.frame.origin.y+scoreStore.frame.size.height+YBKAdaptiveH(5), scoreStore.frame.size.width, scoreStore.frame.size.height) andStyle:HCFindHeaderButtonStoreRecom];
    storeRecom.tag = 3;
    storeRecom.delegate = self;
    storeRecom.backgroundColor = [UIColor whiteColor];
    [self addSubview:storeRecom];
    
    //更多信息
    HCFindHeaderButton *moreStore = [[HCFindHeaderButton alloc] initWithFrame:CGRectMake(hotStore.frame.origin.x, storeRecom.frame.origin.y, storeRecom.frame.size.width, storeRecom.frame.size.height) andStyle:HCFindHeaderButtonMoreStore];
    moreStore.tag = 4;
    moreStore.delegate = self;
    moreStore.backgroundColor = [UIColor whiteColor];
    [self addSubview:moreStore];
    
    //滑动标题栏
    naviView = [[HCFindNaviView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(moreStore.frame) + 5, frame.size.width, YBKAdaptiveH(58))];
    naviView.delegate = self;
    [self addSubview:naviView];
    
    self.adsIMG = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"happy_find_ads"]];
    self.adsIMG.userInteractionEnabled = YES;
    self.adsIMG.frame = CGRectMake(0, ((frame.size.height +YBKAdaptiveH(80)) - YBKAdaptiveH(70))+ YBKAdaptiveH(58), frame.size.width, YBKAdaptiveH(70));
    [self addSubview:self.adsIMG];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tabIMGGesture:)];
    [self.adsIMG addGestureRecognizer:tap];
}

- (void)setNaviNames:(NSArray *)naviNames {

    _naviNames = naviNames;
    naviView.namesArray = naviNames;
}

- (void)clickButtonAction:(NSInteger)index {

    if ([self.delegate respondsToSelector:@selector(clickNaviButton:)]) {
        
        [self.delegate clickNaviButton:index];
    }
}

#pragma mark HCFindHeaderButtonClickedDelegate
-(void)hcFindHeaderButtonClicked:(HCFindHeaderButton *)headerBtn {
    if ([self.delegate respondsToSelector:@selector(happyFindClicked:)]&&self.delegate) {
        [self.delegate happyFindClicked:headerBtn];
    }
    if (headerBtn.tag == 4) {
        [XHToast showBottomWithText:@"敬请期待..."];
    }
}

#pragma mark 图片广告点击代理
-(void)tabIMGGesture:(UITapGestureRecognizer *)tap {
    NSLog(@"图片广告");
}

@end
